from Bio import SeqIO
import sys
import optparse


def merge_fasta(file1, file2):
	"""Merges the two fasta files, and return the list of unique entries"""
	fasta1 = SeqIO.parse(open(file1, "r"), "fasta")
	fasta2 = SeqIO.parse(open(file2, "r"), "fasta")
	
	fasta_entries = {}

	for fasta_file in [fasta1, fasta2]:
		for fasta_entry in fasta_file:
			if fasta_entry.id in fasta_entries.keys():
				pass
			else:
				fasta_entries[fasta_entry.id] = fasta_entry
	
	return [fasta_entries[id] for id in fasta_entries.keys()]


def __main__():
	"""Main Controller"""
	parser = optparse.OptionParser()
	parser.add_option("-1", "--fasta1", default=None, dest="fasta_input",
		help="The first fasta file to use as input")
	parser.add_option("-2","--fasta2", default=None, dest="fasta_input2",
		help="The second fasta file")
	parser.add_option("-o","--output", default=None, dest="output",
		help="The output merged fasta file")
	(options, args) = parser.parse_args()
	
	print merge_fasta(options.fasta_input, options.fasta_input2)

	


if __name__=="__main__":
	__main__()